package com.hr.pong

import com.hr.pong.controller.PongController
import com.hr.pong.service.PongService
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.autoconfigure.web.reactive.WebFluxTest
import org.springframework.boot.test.mock.mockito.MockBean
import org.springframework.test.web.reactive.server.WebTestClient
import reactor.core.publisher.Mono
import spock.lang.Specification

@WebFluxTest(controllers = [PongController])
class PongControllerTest extends Specification {

    @Autowired
    WebTestClient webTestClient

    @MockBean
    PongService pongService

    def "pong should respond with 'World'"() {
        given:
        pongService.pong() >> Mono.just("World")

        when:
        webTestClient.get().uri("/pong")
                .exchange()

        then:
        pongService.pong() == "test"
    }

    /*def "pong should return 429 for too many requests"() {
        given:
        pongService.pong() >> Mono.error(new RuntimeException("Too Many Requests"))

        when:
        webTestClient.get().uri("/pong")
                .exchange()

        then:
        1 * pongService.pong()
    }*/
}
